<template>
  <!-- 几何体方法.setFromPoints -->
  <div>
    <div> 几何体方法.setFromPoints </div>
    <div ref="webgl" id="webgl" style="width: 800px; height: 500px">1212</div>
  </div>
</template>
<script lang="ts" setup>
  import * as THREE from 'three';
  import { OrbitControls } from 'three/addons';
  import { onMounted, ref } from 'vue';

  const webgl: any = ref(null);
  onMounted(() => {
    init();
  });

  function init() {
    const scene = new THREE.Scene();
    const width = 800;
    const height = 500;
    const camera = new THREE.PerspectiveCamera(30, width / height, 1, 10000);
    camera.position.set(-100, 300, 300);
    camera.lookAt(scene.position);
    const render = new THREE.WebGLRenderer();
    render.setSize(width, height);
    console.log(' webgl.value', webgl.value);

    webgl.value.appendChild(render.domElement);
    // document.body.appendChild(render.domElement);
    new OrbitControls(camera, render.domElement);
    const amLight = new THREE.AmbientLight(0xffffff);
    scene.add(amLight);
    const helper = new THREE.AxesHelper(200);
    scene.add(helper);

    const geometryone = new THREE.BoxGeometry(200, 200);
    const material = new THREE.MeshLambertMaterial({ color: 0xff1122 });
    const mesh = new THREE.Mesh(geometryone, material);
    scene.add(mesh);
    function renderFun() {
      // console.log('asdfasdf');

      render.render(scene, camera);
      requestAnimationFrame(renderFun);
    }
    renderFun();
  }
</script>
